package com.ray.controller;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.exception.ServiceException;
import com.ray.pojo.MyUser;
import com.ray.service.EmployeeDailyListService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import com.ray.util.ReturnStringUtil;

@Controller
@RequestMapping("employeeDailyList")
public class EmployeeDailyListController {
	@Autowired
	EmployeeDailyListService employeeDailyListService;

	@RequestMapping("/{methodName}")
	@ResponseBody
	private Map<String, Object> shoppingMallController(HttpServletRequest request,HttpServletResponse response,
			@PathVariable("methodName") String methodName) throws NoSuchMethodException, SecurityException, IllegalAccessException {
		String methodNameMapping=urlMethodMappingMap.get(methodName);
		Map requestParamMap = RequestUtil.getRequestAllParam(request);
		requestParamMap.put("request", request);
		requestParamMap.put("response", response);
		Method targetMethod = employeeDailyListService.getClass().getMethod(methodNameMapping, Map.class);
		Object object=null;
		try {
			 object=targetMethod.invoke(employeeDailyListService, requestParamMap);
		}catch(InvocationTargetException e) {
			if(e.getCause().getClass()== IllegalArgumentException.class || e.getCause().getClass() ==ServiceException.class) {
				e.printStackTrace();
				Assert.notNull(null,e.getTargetException().getMessage());
			}else {
				e.printStackTrace();
				return ResponseUtil.ResponseError(ReturnStringUtil.ERROR);
			}
		}
		return ResponseUtil.ResponseResult(object);
	}


	/**
	 *  方法名和请求路径映射
	 */
	private static  Map<String, String> urlMethodMappingMap;
	static{
		//请求路径
		urlMethodMappingMap=new HashMap<String,String>();
		urlMethodMappingMap.put("addEmployeeDailyNew", "addEmployeeDailyNew");//新的添加员工日报表接口
		urlMethodMappingMap.put("getEmployeeDailyNew", "getEmployeeDailyNew");//获取员工日报表
		urlMethodMappingMap.put("approvalEmployeeDailyListNew", "approvalEmployeeDailyListNew");//审核员工日报表
		urlMethodMappingMap.put("updateEmployeeDailyNew", "updateEmployeeDailyNew");//修改员工日报表
		urlMethodMappingMap.put("deleteEmployeeDailyNew", "deleteEmployeeDailyNew");//删除员工日报表
		urlMethodMappingMap.put("getEmployeeDailyTotal", "getEmployeeDailyTotal");//删除员工日报表
		
		
		//异常申报类型
		urlMethodMappingMap.put("getExceptionType", "getExceptionType");//获取异常类型
		urlMethodMappingMap.put("addExceptionType", "addExceptionType");//添加异常类型
		urlMethodMappingMap.put("updateExceptionType", "updateExceptionType");//修改异常类型
		
		//异常申报单
		urlMethodMappingMap.put("addExceptionDeclare", "addExceptionDeclare");//添加异常申报单
		urlMethodMappingMap.put("getExceptionDeclare", "getExceptionDeclare");//获取异常申报单
		urlMethodMappingMap.put("handOverException", "handOverException");//转交异常申报单
		urlMethodMappingMap.put("endOverException", "endOverException");//解决异常申报单
		urlMethodMappingMap.put("setAnswerDate", "setAnswerDate");//设置复期
		urlMethodMappingMap.put("approvalHandOver", "approvalHandOver");//审核转交
		
		
		
		
		
		
		
		
		//旧方法
		urlMethodMappingMap.put("addEmployeeDailyList", "addEmployeeDailyList");//添加员工日报表
		urlMethodMappingMap.put("getEmployeeDailyList", "getEmployeeDailyList");//获取员工日报表
		urlMethodMappingMap.put("approvalEmployeeDailyList", "approvalEmployeeDailyList");//审核员工日报表
		urlMethodMappingMap.put("deleteEmployeeDailyList", "deleteEmployeeDailyList");//删除员工日报表
		urlMethodMappingMap.put("updateEmployeeDailyList", "updateEmployeeDailyList");//修改员工日报表
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
